package com.iot.broker.mvc.mqtt.controller;

import org.apache.activemq.artemis.jms.client.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.iot.common.core.util.R;

import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/queue")
public class P2PController {
	
	@Autowired
	private JmsTemplate jmsTemplate;
	
	@PostMapping(value = { "/send" }, produces = "application/json; charset=utf-8")
	public R<String> send(@RequestParam(name = "queue", required = true) String queue,@RequestParam(name = "message", required = false) String message) {
		jmsTemplate.convertAndSend(new ActiveMQQueue(queue), message);
		return R.ok();
	}

}
